package com.jshoperxms.controller.api.langdu;

import com.jshoperxms.Response;
import com.jshoperxms.components.wechat.wxcode.WxacodeunlimitController;
import com.jshoperxms.controller.api.langdu.vo.YdRecordRdTVo;
import com.jshoperxms.controller.mall.backstage.base.BaseTController;
import com.jshoperxms.controller.mall.backstage.base.SearchModel;
import com.jshoperxms.controller.utils.BaseTools;
import com.jshoperxms.controller.utils.DateTools;
import com.jshoperxms.controller.utils.PrimaryKey;
import com.jshoperxms.controller.utils.enums.BaseEnums;
import com.jshoperxms.controller.utils.statickey.StaticKey;
import com.jshoperxms.controller.utils.statickey.TagWords;
import com.jshoperxms.controller.utils.statickey.WarnWrods;
import com.jshoperxms.entity.*;
import com.jshoperxms.service.*;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.http.HttpRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by sdywcd on 2018/9/29.
 * Des:
 */
@RestController
@RequestMapping("/api/record")
public class RecordController extends BaseTController {

    @Resource
    private WxacodeunlimitController wxacodeunlimitController;
    @Resource
    private MemberTService memberTService;

    @Resource
    private YdTeamTService ydTeamTService;

    @Resource
    private YdRecordRdTService ydRecordRdTService;

    @Resource
    private YdStatusInfoTSerivce ydStatusInfoTSerivce;

    @Resource
    private YdRecordCommentTService ydRecordCommentTService;

    @Resource
    private SysWxpushRpTService sysWxpushRpTService;

    @Resource
    private YdArticleRecordRdTService ydArticleRecordRdTService;

    @Resource
    private YdRecordCategoryTService ydRecordCategoryTService;


    @RequestMapping(value="/updateAllRdMemberId",method= RequestMethod.POST)
    public ResponseEntity updateAllRdMemberId(){
        List<YdRecordRdT>list=this.ydRecordRdTService.findAll(YdRecordRdT.class);
        for(YdRecordRdT yd:list){
            Criterion criterion= Restrictions.eq("wxopenid",yd.getWxopenid());
            MemberT memberT=this.memberTService.findOneByCriteria(MemberT.class,criterion);
            if(memberT!=null){
                yd.setMemberid(memberT.getId());
                this.ydRecordRdTService.update(yd);
            }
        }
        List<YdRecordCommentT>list222=this.ydRecordCommentTService.findAll(YdRecordCommentT.class);
        for(YdRecordCommentT yt:list222){

            YdRecordRdT ydRecordRdT=this.ydRecordRdTService.findByPK(YdRecordRdT.class, yt.getRecordid());
            if(ydRecordRdT!=null){
                yt.setTargetmemberid(ydRecordRdT.getMemberid());
                yt.setTargetwxopenid(ydRecordRdT.getWxopenid());
                this.ydRecordCommentTService.update(yt);
            }
        }
        return Response.success("1");
    }

    /**
     * 获取下一次阅读次数
     * @param rq
     * @return
     */
    @RequestMapping(value="/getNextYuduTime",method= RequestMethod.POST)
    public ResponseEntity getNextYuduT(@RequestBody YdRecordRdT rq){
        Map<String,Object> responsedata=new HashMap<>();
        if(StringUtils.isNotBlank(rq.getWxopenid())){
            Criterion criterion=Restrictions.eq("wxopenid",rq.getWxopenid());
            YdStatusInfoT bean=this.ydStatusInfoTSerivce.findOneByCriteria(YdStatusInfoT.class,criterion);
            if(bean!=null){
                responsedata.put("nextydper",bean.getNextydper());
                responsedata.put(TagWords.SUCCESS,true);
            }else{
                responsedata.put(TagWords.SUCCESS,true);
                responsedata.put("nextydper",1);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
        }
        return Response.success(responsedata);
    }



    /**
     * 保存朗读记录
     * @param rq
     * @return
     */
    @RequestMapping(value="/saveRecord",method= RequestMethod.POST)
    public ResponseEntity saveRecord(@RequestBody YdRecordRdTVo rq){
        Map<String,Object> responsedata=new HashMap<>();
        if(StringUtils.isNotBlank(rq.getWxopenid())){
            Criterion criterion= Restrictions.eq("wxopenid",rq.getWxopenid());
            MemberT memberT=this.memberTService.findOneByCriteria(MemberT.class,criterion);
            if(memberT!=null){
                YdRecordRdT bean=new YdRecordRdT();
                bean.setId(PrimaryKey.get().toString());
                bean.setFileurl(rq.getFileurl());
                bean.setStatus(BaseEnums.DataUsingState.USING.getState());
                bean.setCreatetime(DateTools.getSystemTimeLong());
                bean.setCreatorid("0");
                bean.setUpdatetime(DateTools.getSystemTimeLong());
                bean.setVersiont(1);
                bean.setDuration(rq.getDuration());
                bean.setGbiaoyang(0);
                bean.setGleafs(20);
                bean.setGscore(90);
                bean.setGruntimecount(1);
                bean.setGsharecount(0);
                bean.setFilebgimg(StaticKey.EMPTY);
                bean.setFilerparticlesid(StaticKey.EMPTY);
                bean.setFilerpvideosid(StaticKey.EMPTY);
                if(StringUtils.isNotBlank(rq.getAuthorheadimg())){
                    bean.setAuthorheadimg(rq.getAuthorheadimg());
                }else{
                    bean.setAuthorheadimg(memberT.getHeadpath());
                }
                if(StringUtils.isNotBlank(rq.getAuthornick())){
                    bean.setAuthornick(rq.getAuthornick());
                }else{
                    bean.setAuthornick(memberT.getNick());
                }
                bean.setWxopenid(rq.getWxopenid());
                bean.setFiletype(rq.getFiletype());
                bean.setCurrentpublishcount(rq.getCurrentpublishcount());
                bean.setTitle(rq.getTitle());
                bean.setDefaultduration("00:00");
                if(StringUtils.isNotBlank(rq.getIspublic())){
                    bean.setIspublic(rq.getIspublic());
                }
                bean.setTeamcategory(StaticKey.EMPTY);
                bean.setTeamcategoryid("0");
                bean.setRecommend("0");//不推荐
                bean.setFollowuprdid(StaticKey.EMPTY);
                bean.setFollowupreading("0");//不是跟读内容
                bean.setMemberid(memberT.getId());
                bean.setTeamid(StaticKey.EMPTY);
                bean.setRdcategoryid("1");
                bean.setRdcategoryname("默认");
                this.ydRecordRdTService.save(bean);
                //把记录的主键放到rq对象中
                rq.setId(bean.getId());
                updateYdStatusLangdu(bean.getWxopenid());
                //保存推送的formid
                saveOrUpdateWxPushFormid(rq);
                responsedata.put(TagWords.SUCCESS,true);
                responsedata.put("recordid",bean.getId());
            }else{
                responsedata.put(TagWords.SUCCESS,false);
                responsedata.put(TagWords.MSG, WarnWrods.ERROR_PARAMS);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
            responsedata.put(TagWords.MSG, WarnWrods.ERROR_PARAMS);
        }
        return Response.success(responsedata);
    }


    private void saveOrUpdateWxPushFormid(YdRecordRdTVo rq){
        if(StringUtils.isNotBlank(rq.getFormid())&&StringUtils.isNotBlank(rq.getWxopenid())){
            //查询是否有formid
            Criterion criterion=Restrictions.eq("wxopenid",rq.getWxopenid());
            SysWxpushRpT bean=this.sysWxpushRpTService.findOneByCriteria(SysWxpushRpT.class,criterion);
            if(bean!=null){
                bean.setFormid(rq.getFormid());
                this.sysWxpushRpTService.update(bean);
            }else {
                bean=new SysWxpushRpT();
                bean.setId(PrimaryKey.get().toString());
                bean.setWxopenid(rq.getWxopenid());
                bean.setFormid(rq.getFormid());
                bean.setAction("comment");
                this.sysWxpushRpTService.save(bean);
            }
        }
    }


    /**
     * 更新小队状态数据
     * @param teamid
     */
    public void updateTeamStatus(String teamid){
        YdTeamT bean=this.ydTeamTService.findByPK(YdTeamT.class,teamid);
        if(bean!=null){
            bean.setTotalleafs(bean.getTotalleafs()+5);
            this.ydTeamTService.update(bean);

        }
    }

    /**
     * 更新阅读次数,下次阅读次数，奖励树叶
     * @param wxopenid
     */
    public void updateYdStatusLangdu(String wxopenid){
        Criterion criterion=Restrictions.eq("wxopenid",wxopenid);
        YdStatusInfoT bean=this.ydStatusInfoTSerivce.findOneByCriteria(YdStatusInfoT.class,criterion);
        if(bean!=null){
            bean.setTotalyuedu(bean.getTotalyuedu()+1);
            bean.setNextydper(bean.getNextydper()+1);
            bean.setTotalleafs(bean.getTotalleafs()+20);
            this.ydStatusInfoTSerivce.update(bean);
        }
    }


    /**
     * 获取乐园中的朗读数据
     * @param rq
     * @return
     */
    @RequestMapping(value="/findLeYuanResutls",method= RequestMethod.POST)
    public ResponseEntity findLeYuanIndexResutl(@RequestBody SearchModel rq){
        Map<String,Object> responsedata=new HashMap<>();
        int currentPage=rq.getStart();
        int lineSize=rq.getLength();
        Criterion criterion=Restrictions.and(Restrictions.eq("ispublic","1")).add(Restrictions.eq(TagWords.STATUS, BaseEnums.DataUsingState.USING.getState()));
        int records=this.ydRecordRdTService.count(YdRecordRdT.class,criterion).intValue();
        List<YdRecordRdT> list=this.ydRecordRdTService.findByCriteriaByPage(YdRecordRdT.class,criterion, Order.desc(TagWords.CREATETIME),currentPage,lineSize);
        rq.setRecordsTotal(records);
        responsedata.put("results",list);
        responsedata.put("start",rq.getNextPageNo());
        responsedata.put("totalPage",rq.getTotalPage());
        responsedata.put(TagWords.SUCCESS,true);
        return Response.success(responsedata);
    }


    /**
     * 更新阅读表扬
     * @param rq
     * @return
     */
    @RequestMapping(value="/updateYdBiaoyang",method= RequestMethod.POST)
    public ResponseEntity updateYdBiaoyang(@RequestBody YdRecordRdT rq){
        Map<String,Object> responsedata=new HashMap<>();
        if(StringUtils.isNotBlank(rq.getId())){
            YdRecordRdT bean=this.ydRecordRdTService.findByPK(YdRecordRdT.class,rq.getId());
            if(bean!=null){
                bean.setUpdatetime(DateTools.getSystemTimeLong());
                bean.setGbiaoyang(bean.getGbiaoyang()+1);
                bean.setVersiont(bean.getVersiont()+1);
                this.ydRecordRdTService.update(bean);
                updateYdStatus(bean.getWxopenid());
                responsedata.put(TagWords.SUCCESS,true);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
        }
        return Response.success(responsedata);
    }


    public void updateYdStatus(String wxopenid){
        Criterion criterion=Restrictions.eq("wxopenid",wxopenid);
        YdStatusInfoT bean=this.ydStatusInfoTSerivce.findOneByCriteria(YdStatusInfoT.class,criterion);
        if(bean!=null){
            bean.setTotalbiaoyang(bean.getTotalbiaoyang()+1);
            this.ydStatusInfoTSerivce.update(bean);
        }

    }




    /**
     * 更新播放次数
     * @param rq
     * @return
     */
    @RequestMapping(value="/updateYdTims",method= RequestMethod.POST)
    public ResponseEntity updateYdTims(@RequestBody YdRecordRdT rq){
        Map<String,Object> responsedata=new HashMap<>();
        if(StringUtils.isNotBlank(rq.getId())){
            YdRecordRdT bean=this.ydRecordRdTService.findByPK(YdRecordRdT.class,rq.getId());
            if(bean!=null){
                bean.setUpdatetime(DateTools.getSystemTimeLong());
                bean.setGruntimecount(bean.getGruntimecount()+1);
                bean.setVersiont(bean.getVersiont()+1);
                this.ydRecordRdTService.update(bean);
                responsedata.put(TagWords.SUCCESS,true);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
        }
        return Response.success(responsedata);
    }


    /**
     * 更新分享次数
     * @param rq
     * @return
     */
    @RequestMapping(value="/updateShares",method= RequestMethod.POST)
    public ResponseEntity updateShares(@RequestBody YdRecordRdT rq){
        Map<String,Object> responsedata=new HashMap<>();
        if(StringUtils.isNotBlank(rq.getId())){
            YdRecordRdT bean=this.ydRecordRdTService.findByPK(YdRecordRdT.class,rq.getId());
            if(bean!=null){
                bean.setUpdatetime(DateTools.getSystemTimeLong());
                bean.setGsharecount(bean.getGsharecount()+1);
                bean.setVersiont(bean.getVersiont()+1);
                this.ydRecordRdTService.update(bean);
                updateTotalShares(bean.getWxopenid());
                responsedata.put(TagWords.SUCCESS,true);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
        }
        return Response.success(responsedata);
    }


    /**
     * 更新分享总数//赠送5个树叶
     * @param wxopenid
     */
    public void updateTotalShares(String wxopenid){
        Criterion criterion=Restrictions.eq("wxopenid",wxopenid);
        YdStatusInfoT bean=this.ydStatusInfoTSerivce.findOneByCriteria(YdStatusInfoT.class,criterion);
        if(bean!=null){
            bean.setTotalshare(bean.getTotalshare()+1);
            bean.setTotalleafs(bean.getTotalleafs()+5);
            this.ydStatusInfoTSerivce.update(bean);
        }
    }


    /**
     * 根据id获取朗读数据
     * @param rq
     * @return
     */
    @RequestMapping(value="/findOneRecodById",method= RequestMethod.POST)
    public ResponseEntity findOneRecodById(@RequestBody YdRecordRdT rq){
        Map<String,Object> responsedata=new HashMap<>();
        if(StringUtils.isNotBlank(rq.getId())){
            YdRecordRdT bean=this.ydRecordRdTService.findByPK(YdRecordRdT.class,rq.getId());
            if(bean!=null){
                responsedata.put("publishtime",DateTools.formateLongDateToString(bean.getCreatetime()));
                responsedata.put(TagWords.BEAN,bean);
                responsedata.put(TagWords.SUCCESS,true);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
        }
        return Response.success(responsedata);
    }

    /**
     * 获取会员小队文章朗读信息
     * @param rq
     * @return
     */
    @RequestMapping(value="/findMemberTeamArtRecordInfo",method= RequestMethod.POST)
    public ResponseEntity findMemberTeamArtRecordInfo(@RequestBody YdRecordRdT rq){
        Map<String,Object> responsedata=new HashMap<>();
        if(StringUtils.isNotBlank(rq.getId())){
            YdRecordRdT bean=this.ydRecordRdTService.findByPK(YdRecordRdT.class,rq.getId());
            if(bean!=null){
                YdArticleRecordRdT articleRecordRdT=this.ydArticleRecordRdTService.findByPK(YdArticleRecordRdT.class,bean.getFollowuprdid());
                if(articleRecordRdT!=null){
                    responsedata.put("articlerecord",articleRecordRdT);
                }
                if(StringUtils.isNotBlank(bean.getTeamid())){
                    YdTeamT ydTeamT=this.ydTeamTService.findByPK(YdTeamT.class,bean.getTeamid());
                    if(ydTeamT!=null){
                        responsedata.put("teamname",ydTeamT.getTeamname());
                    }
                }
                responsedata.put("publishtime",DateTools.formateLongDateToString(bean.getCreatetime()));
                responsedata.put(TagWords.BEAN,bean);
                responsedata.put(TagWords.SUCCESS,true);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
        }
        return Response.success(responsedata);
    }


    /**
     * 保存图文朗读记录
     * @param rq
     * @return
     */
    @RequestMapping(value="/saveArtRecord",method= RequestMethod.POST)
    public ResponseEntity saveArtRecord(@RequestBody YdRecordRdTVo rq) {
        Map<String, Object> responsedata = new HashMap<>();
        if (StringUtils.isNotBlank(rq.getWxopenid()) && StringUtils.isNotBlank(rq.getArtrecordid())) {
            Criterion criterion= Restrictions.eq("wxopenid",rq.getWxopenid());
            MemberT memberT=this.memberTService.findOneByCriteria(MemberT.class,criterion);
            if(memberT!=null){
                YdRecordRdT bean=new YdRecordRdT();
                bean.setId(PrimaryKey.get().toString());
                bean.setFileurl(rq.getFileurl());
                bean.setStatus(BaseEnums.DataUsingState.USING.getState());
                bean.setCreatetime(DateTools.getSystemTimeLong());
                bean.setCreatorid("0");
                bean.setUpdatetime(DateTools.getSystemTimeLong());
                bean.setVersiont(1);
                bean.setDuration(rq.getDuration());
                bean.setGbiaoyang(0);
                bean.setGleafs(20);
                bean.setGscore(90);
                bean.setGruntimecount(1);
                bean.setGsharecount(0);
                bean.setFilebgimg(StaticKey.EMPTY);
                bean.setFilerparticlesid(StaticKey.EMPTY);
                bean.setFilerpvideosid(StaticKey.EMPTY);
                bean.setAuthorheadimg(memberT.getHeadpath());
                bean.setAuthornick(memberT.getNick());
                bean.setWxopenid(rq.getWxopenid());
                bean.setFiletype(rq.getFiletype());
                bean.setCurrentpublishcount(rq.getCurrentpublishcount());
                bean.setTitle(rq.getTitle());
                bean.setDefaultduration("00:00");
                if(StringUtils.isNotBlank(rq.getIspublic())){
                    bean.setIspublic(rq.getIspublic());
                }
                bean.setTeamcategoryid(rq.getTeamcategoryid());
                bean.setTeamcategory(rq.getTeamcategory());
                bean.setRecommend("0");//不推荐
                bean.setFollowuprdid(rq.getArtrecordid());
                bean.setFollowupreading("1");
                bean.setMemberid(memberT.getId());
                bean.setTeamid(rq.getTeamid());
                this.ydRecordRdTService.save(bean);
                //把记录的主键放到rq对象中
                rq.setId(bean.getId());
                updateYdStatusLangdu(bean.getWxopenid());
                updateArtRecordFollowingCount(rq.getArtrecordid());
                updateTeamStatus(rq.getTeamid());
                responsedata.put(TagWords.SUCCESS,true);
                responsedata.put("recordid",bean.getId());
            }else{
                responsedata.put(TagWords.SUCCESS,false);
                responsedata.put(TagWords.MSG, WarnWrods.ERROR_PARAMS);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
            responsedata.put(TagWords.MSG, WarnWrods.ERROR_PARAMS);
        }
        return Response.success(responsedata);

    }

    /**
     * 保存小队中的自定义朗读记录
     * @param rq
     * @return
     */
    @RequestMapping(value="/saveTeamCustomRecord",method= RequestMethod.POST)
    public ResponseEntity saveTeamCustomRecord(@RequestBody YdRecordRdTVo rq) {
        Map<String, Object> responsedata = new HashMap<>();
        if (StringUtils.isNotBlank(rq.getWxopenid())) {
            Criterion criterion= Restrictions.eq("wxopenid",rq.getWxopenid());
            MemberT memberT=this.memberTService.findOneByCriteria(MemberT.class,criterion);
            if(memberT!=null){
                YdRecordRdT bean=new YdRecordRdT();
                bean.setId(PrimaryKey.get().toString());
                bean.setFileurl(rq.getFileurl());
                bean.setStatus(BaseEnums.DataUsingState.USING.getState());
                bean.setCreatetime(DateTools.getSystemTimeLong());
                bean.setCreatorid("0");
                bean.setUpdatetime(DateTools.getSystemTimeLong());
                bean.setVersiont(1);
                bean.setDuration(rq.getDuration());
                bean.setGbiaoyang(0);
                bean.setGleafs(20);
                bean.setGscore(90);
                bean.setGruntimecount(1);
                bean.setGsharecount(0);
                bean.setFilebgimg(StaticKey.EMPTY);
                bean.setFilerparticlesid(StaticKey.EMPTY);
                bean.setFilerpvideosid(StaticKey.EMPTY);
                bean.setAuthorheadimg(memberT.getHeadpath());
                bean.setAuthornick(memberT.getNick());
                bean.setWxopenid(rq.getWxopenid());
                bean.setFiletype(rq.getFiletype());
                bean.setCurrentpublishcount(rq.getCurrentpublishcount());
                bean.setTitle(rq.getTitle());
                bean.setDefaultduration("00:00");
                if(StringUtils.isNotBlank(rq.getIspublic())){
                    bean.setIspublic(rq.getIspublic());
                }
                bean.setTeamcategoryid(rq.getTeamcategoryid());
                bean.setTeamcategory(rq.getTeamcategory());
                bean.setRecommend("0");//不推荐
                bean.setFollowuprdid(StaticKey.EMPTY);
                bean.setFollowupreading("0");
                bean.setMemberid(memberT.getId());
                bean.setTeamid(rq.getTeamid());
                this.ydRecordRdTService.save(bean);
                //把记录的主键放到rq对象中
                rq.setId(bean.getId());
                updateYdStatusLangdu(bean.getWxopenid());
                updateTeamStatus(rq.getTeamid());
                //保存推送的formid
                saveOrUpdateWxPushFormid(rq);
                responsedata.put(TagWords.SUCCESS,true);
                responsedata.put("recordid",bean.getId());
            }else{
                responsedata.put(TagWords.SUCCESS,false);
                responsedata.put(TagWords.MSG, WarnWrods.ERROR_PARAMS);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
            responsedata.put(TagWords.MSG, WarnWrods.ERROR_PARAMS);
        }
        return Response.success(responsedata);

    }

    /**
     * 更新图文朗读的跟读数量
     * @param artrecordid
     */
    private void updateArtRecordFollowingCount(String artrecordid){
        YdArticleRecordRdT bean=this.ydArticleRecordRdTService.findByPK(YdArticleRecordRdT.class,artrecordid);
        if(bean!=null){
            bean.setGfollowreadingcount(bean.getGfollowreadingcount()+1);
            bean.setVersiont(bean.getVersiont()+1);
            this.ydArticleRecordRdTService.update(bean);
        }
    }

    /**
     * 获取我的录音分类信息
     * @param rq
     * @return
     */
    @RequestMapping(value="/findMRecordCategorys",method= RequestMethod.POST)
    public ResponseEntity findMRecordCategorys(@RequestBody YdRecordCategoryT rq) {
        Map<String, Object> responsedata = new HashMap<>();
        if (StringUtils.isNotBlank(rq.getWxopenid())) {
            Criterion criterion=Restrictions.and(Restrictions.eq("wxopenid",rq.getWxopenid())).add(Restrictions.eq(TagWords.STATUS,BaseEnums.DataUsingState.USING.getState()));
            List<YdRecordCategoryT>beanlist=this.ydRecordCategoryTService.findByCriteria(YdRecordCategoryT.class,criterion,Order.desc(TagWords.CREATETIME));
            responsedata.put(TagWords.BEANLIST,beanlist);
            responsedata.put(TagWords.SUCCESS,true);
        }else{
            responsedata.put(TagWords.SUCCESS,false);
            responsedata.put(TagWords.MSG, WarnWrods.ERROR_PARAMS);
        }
        return Response.success(responsedata);

    }

    /**
     * 保存新的录音分类
     * @param rq
     * @return
     */
    @RequestMapping(value="/saveRecordCategory",method= RequestMethod.POST)
    public ResponseEntity saveRecordCategory(@RequestBody YdRecordCategoryT rq){
        Map<String, Object> responsedata = new HashMap<>();
        if (StringUtils.isNotBlank(rq.getWxopenid()) && StringUtils.isNotBlank(rq.getCategoryname())) {
            Criterion criterion = Restrictions.and(Restrictions.eq("wxopenid",rq.getWxopenid())).add(Restrictions.eq("categoryname",rq.getCategoryname()));
            YdRecordCategoryT bean=this.ydRecordCategoryTService.findOneByCriteria(YdRecordCategoryT.class,criterion);
            if(bean==null){
                bean=new YdRecordCategoryT();
                bean.setId(PrimaryKey.get().toString());
                bean.setStatus(BaseEnums.DataUsingState.USING.getState());
                bean.setCreatetime(DateTools.getSystemTimeLong());
                bean.setWxopenid(rq.getWxopenid());
                bean.setUpdatetime(DateTools.getSystemTimeLong());
                bean.setVersiont(1);
                bean.setCategoryname(rq.getCategoryname());
                this.ydRecordCategoryTService.save(bean);
                responsedata.put(TagWords.SUCCESS,true);
            }else{
                responsedata.put(TagWords.SUCCESS,true);
                responsedata.put(TagWords.MSG,WarnWrods.ERROR_HAVE_KEY);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
            responsedata.put(TagWords.MSG, WarnWrods.ERROR_PARAMS);

        }
        return Response.success(responsedata);
    }


    /**
     * 更新录音分类
     * @param rq
     * @return
     */
    @RequestMapping(value="/updateRecordCategory",method= RequestMethod.POST)
    public ResponseEntity updateRecordCategory(@RequestBody YdRecordRdT rq) {
        Map<String, Object> responsedata = new HashMap<>();
        if (StringUtils.isNotBlank(rq.getId()) && StringUtils.isNotBlank(rq.getRdcategoryid())&&StringUtils.isNotBlank(rq.getRdcategoryname())) {
            YdRecordRdT ydRecordRdT=this.ydRecordRdTService.findByPK(YdRecordRdT.class,rq.getId());
            if(ydRecordRdT!=null){
                ydRecordRdT.setRdcategoryid(rq.getRdcategoryid());
                ydRecordRdT.setRdcategoryname(rq.getRdcategoryname());
                ydRecordRdT.setUpdatetime(DateTools.getSystemTimeLong());
                responsedata.put(TagWords.SUCCESS,true);
                this.ydRecordRdTService.update(ydRecordRdT);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
            responsedata.put(TagWords.MSG, WarnWrods.ERROR_PARAMS);

        }
        return Response.success(responsedata);
    }


    /**
     * 生成音频朗读小程序二维码
     * @param rq
     * @return
     */
    @RequestMapping(value="/createYdrecordWxCode",method= RequestMethod.POST)
    public ResponseEntity createYdrecordWxCode(HttpServletRequest request, @RequestBody YdRecordRdT rq) throws IOException{
        Map<String, Object> responsedata = new HashMap<>();
        if(StringUtils.isNotBlank(rq.getId())){
            String senceparams=rq.getId();
            responsedata=wxacodeunlimitController.createYdRecordWxCode(request,senceparams);
            if(responsedata.get("wxcodeurl")!=null){
                responsedata.put(TagWords.SUCCESS,true);
            }
        }else{
            responsedata.put(TagWords.SUCCESS,false);
        }
        return Response.success(responsedata);
    }


}
